package com.company.planner.entity;

import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.cuba.core.entity.StandardEntity;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;

@Table(name = "PLANNER_HOT_WORDS", indexes = {
        @Index(name = "IDX_PLANNER_HOT_WORDS_WORD", columnList = "WORD")
})
@Entity(name = "planner_HotWords")
@NamePattern("%s|word")
public class HotWords extends StandardEntity {
    private static final long serialVersionUID = -3277215203826122673L;

    @NotNull(message = "{msg://planner_HotWords.word.validation.NotNull}")
    @Column(name = "WORD", nullable = false, unique = true)
    private String word;

    @Column(name = "SWITCH_STATE", nullable = false)
    @NotNull(message = "{msg://planner_HotWords.switchState.validation.NotNull}")
    private Integer switchState;

    @OneToMany(mappedBy = "word")
    private List<HotOperationRecord> operationRecords;

    public List<HotOperationRecord> getOperationRecords() {
        return operationRecords;
    }

    public void setOperationRecords(List<HotOperationRecord> operationRecords) {
        this.operationRecords = operationRecords;
    }

    public SwitchEnum getSwitchState() {
        return switchState == null ? null : SwitchEnum.fromId(switchState);
    }

    public void setSwitchState(SwitchEnum switchState) {
        this.switchState = switchState == null ? null : switchState.getId();
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }
}